<?php

namespace App\Http\Middleware;

use App\Jobs\SaveSubscribeUser;
use App\Repository\UserRepository;
use Closure;

class WechatSubscribe
{

    protected $user;

    public function __construct(UserRepository $user)
    {
        $this->user = $user;
    }
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        $user = \Auth::guard('wechat')->user();

        if($user && !$user->deleted_at){

            return $next($request);

        }

        return redirect('error/subscribe');
    }
}
